<?php
class C_Base extends CI_Controller {
	
	var $current_user = null;
	var $page_size = 15;
	var $validate_result = false;
	var $validate_redirect = true;
	
	function __construct()
    {
        parent::__construct();
		$this->load->library('session');
		$this->load->helper('url');
		$this->lang->load('common');
    }
	
	/*
	 * 验证用户登陆
	 */
	protected function validate_login(){
		$user = $this->session->userdata('logined_user');
		$this->validate_result = false;
		if($user && $user->user_id>0){
			$this->current_user = $user;
			$this->validate_result = true;
		}
		else{
			if($this->validate_redirect){
				redirect('/users/login');
			}
		}
	}
	
	/*
	 * 创建分页HTML
	 */
	protected function create_pager_render($base_url, $total_num, $size=NULL){
		$this->load->library('pagination');
		if($size == NULL)$size = $this->page_size;
		$config['base_url'] = $base_url;
		$config['total_rows'] = $total_num;
		$config['per_page'] = $size; 
		$config['num_links'] = 10; 
		$config['use_page_numbers'] = TRUE;	
		$config['first_link'] = $this->lang->line('button_first');
		$config['last_link'] = $this->lang->line('button_last');		
		
		$this->pagination->initialize($config); 
		
		return $this->pagination->create_links();
	}
}